home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
WINDOWS
/
MDIT.ARJ
/
FRAME.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-31
|
17KB
|
562 lines
/****************************************************************************
Module name: MDIT.C
Programmer : Jeffrey M. Richter & Elvira Peretsman.
Modified : V. M. Vanderburg & M.T. Peterson, TriTechnologies
- Converted to multithreading
- Removed original comments
ATTRIBUTIONS:
With the exception of the PCthread calls, this code was taken directly
from the source disk furnished with the Windows Developer's Guide,
M&T Press, by Jeffrey M. Richter. I highly recommend Mr. Richter's
book both for its readability and the structure and quality of the
code.
*****************************************************************************/
/*
#include "..\nowindws.h"
#undef NOCOLOR
#undef NOCTLMGR
#undef NODEFERWINDOWPOS
#undef NOGDI
#undef NOKERNEL
#undef NOLSTRING
#undef NOMB
#undef NOMDI
#undef NOMENUS
#undef NOMINMAX
#undef NONCMESSAGES
#undef NOSCROLL
#undef NOSHOWWINDOW
#undef NOSYSCOMMANDS
#undef NOSYSMETRICS
#undef NOTEXTMETRIC
#undef NOUSER
#undef NOWH
#undef NOWINMESSAGES
#undef NOWINOFFSETS
#undef NOWINSTYLES
#define OEMRESOURCE
*/
#include <windows.h>
#define OBM_CLOSE 32754 /* don't know why this is needed */
#include "mdit.h" /* includes pcthread.h */
extern th_list_p_t g_th_list_p;
static char _szClassName[] = "Frame";
typedef struct {
WORD wNumThreads; // Number of Thread windows created.
HMENU hMenu; // Menu used when no MDIT Children are active.
BOOL fStatusBarOn; // Is the status bar showing.
HWND hWndMenuHelp; // Window that last received a WM_MENUSELECT message.
DWORD dwMenuHelp; // Menu help code placed here by hWndMenuHelp window.
} CLSEB;
void NEAR PASCAL TileVertically (HWND hWndMDITClient);
BOOL FAR PASCAL AboutProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam);
LONG FAR PASCAL FrameWndProc (HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
BOOL fCallDefProc = FALSE;
DWORD dwResult = 0;
CLIENTCREATESTRUCT ccs;
HMENU hMenu;
RECT rc, rcTemp;
WORD wTemp = 0;
FARPROC fpProc;
char szBuf[100];
PAINTSTRUCT ps;
TEXTMETRIC tm;
HPEN hPen;
BITMAP Bitmap;
HWND hWndActiveMDITChild, hWndChild;
BOOL fMDITChildIsMaximized;
th_list_p_t cur_p;
th_list_p_t next_p;
if (IsWindow(g_hWndMDITClient))
dwResult = SendMessage(g_hWndMDITClient, WM_MDIGETACTIVE, 0, 0);
hWndActiveMDITChild = (HWND) LOWORD(dwResult);
fMDITChildIsMaximized = HIWORD(dwResult);
dwResult = 0;
switch (wMsg)
{
case WM_CREATE:
hMenu = LoadMenu(g_hInstance, _szClassName);
SETCLSEB(hWnd, CLSEB, hMenu, hMenu);
SETCLSEB(hWnd, CLSEB, fStatusBarOn, TRUE);
ccs.hWindowMenu = GetSubMenu(GetMenu(hWnd), 1);
ccs.idFirstChild = IDM_WINDOWCHILD;
g_hWndMDITClient = CreateWindow("MDIClient", "",
WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL |
WS_VISIBLE | WS_CLIPSIBLINGS, 0, 0, 0, 0, hWnd, NULL, g_hInstance,
(LPSTR) (LPCLIENTCREATESTRUCT) &ccs);
break;
case WM_CLOSE:
fCallDefProc = TRUE;
SendMessage(hWnd, WM_ENDSESSION, TRUE, 0);
break;
case WM_QUERYENDSESSION:
dwResult = TRUE;
break;
case WM_ENDSESSION:
hWndChild = GetWindow(g_hWndMDITClient, GW_CHILD);
if (hWndChild == NULL)
break;
do
{
if (GetWindow(hWndChild, GW_OWNER) != NULL) continue;
SendMessage(hWndChild, WM_ENDSESSION, wParam, 0);
} while ((hWndChild = GetWindow(hWndChild, GW_HWNDNEXT)) != NULL);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_SYSCOMMAND:
SetFocus(hWnd);
fCallDefProc = TRUE;
break;
case WM_NCLBUTTONDBLCLK:
fCallDefProc = TRUE;
if (wParam != HTMENU)
break;
dwResult = SendMessage(g_hWndMDITClient, WM_MDIGETACTIVE, 0, 0);
if (HIWORD(dwResult) != 1)
break;
GetWindowRect(hWnd, &rc);
wTemp = LoadBitmap(NULL, MAKEINTRESOURCE(OBM_CLOSE));
GetObject((HBITMAP) wTemp, sizeof(BITMAP), (LPSTR) (LPBITMAP) &Bitmap);
DeleteObject((HBITMAP) wTemp);
rc.top += GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME);
rc.bottom = rc.top + Bitmap.bmHeight;
rc.left += GetSystemMetrics(SM_CXFRAME);
rc.right = rc.left + Bitmap.bmWidth / 2;
if (!PtInRect(&rc, MAKEPOINT(lParam)))
break;
SendMessage(LOWORD(dwResult), WM_SYSCOMMAND, SC_CLOSE, lParam);
fCallDefProc = FALSE;
break;
case FW_MDITCHILDDESTROY:
if (hWndActiveMDITChild != NULL)
break;
ChangeMDITMenu(hWnd, g_hWndMDITClient,
(HMENU) GETCLSEB(hWnd, CLSEB, hMenu), IDM_WINDOWTILEVERT);
g_hAccelTable = NULL;
InvalidateRect(hWnd, NULL, TRUE);
break;
case FW_GETSTATBARRECT:
GetClientRect(hWnd, (LPRECT) lParam);
if (!GETCLSEB(hWnd, CLSEB, fStatusBarOn))
{
((LPRECT) lParam)->top = ((LPRECT) lParam)->bottom;
break;
}
wTemp = GetDC(hWnd);
GetTextMetrics((HDC) wTemp, &tm);
ReleaseDC(hWnd, (HDC) wTemp);
((LPRECT) lParam)->top =
((LPRECT) lParam)->bottom -
tm.tmHeight - GetSystemMetrics(SM_CYBORDER);
break;
case FW_DRAWSTATUSDIVIDE:
dwResult = GetSystemMetrics(SM_CYBORDER);
hPen = CreatePen(PS_SOLID, (int) dwResult, RGB(0, 0, 0));
hPen = SelectObject(((LPPAINTSTRUCT) lParam)->hdc, hPen);
MoveTo(((LPPAINTSTRUCT) lParam)->hdc, 0,
((LPPAINTSTRUCT) lParam)->rcPaint.top);
LineTo(((LPPAINTSTRUCT) lParam)->hdc,
((LPPAINTSTRUCT) lParam)->rcPaint.right,
((LPPAINTSTRUCT) lParam)->rcPaint.top);
hPen = SelectObject(((LPPAINTSTRUCT) lParam)->hdc, hPen);
DeleteObject(hPen);
break;
case FW_RESIZEMDITCLIENT:
GetClientRect(hWnd, &rc);
SendMessage(hWnd, FW_GETSTATBARRECT, 0, (LONG) (LPRECT) &rcTemp);
rc.bottom -= rcTemp.bottom - rcTemp.top;
MoveWindow(g_hWndMDITClient, 0, rc.top, rc.right, rc.bottom, TRUE);
break;
case WM_SIZE:
SendMessage(hWnd, FW_RESIZEMDITCLIENT, 0, 0);
break;
case WM_PAINT:
BeginPaint(hWnd, &ps);
SendMessage(hWnd, FW_GETSTATBARRECT, 0, (LONG) (LPRECT) &ps.rcPaint);
SetBkMode(ps.hdc, TRANSPARENT);
if (hWndActiveMDITChild)
{
SendMessage(hWndActiveMDITChild, AC_PAINTSTATBAR, ps.hdc,
(LONG) (LPPAINTSTRUCT) &ps);
}
else
{
ps.rcPaint.top += (int) SendMessage(hWnd, FW_DRAWSTATUSDIVIDE, 0,
(LONG) (LPPAINTSTRUCT) &ps);
LoadString(g_hInstance, IDS_FRAMESTATUSBAR, szBuf, sizeof(szBuf));
TextOut(ps.hdc, 0, ps.rcPaint.top, szBuf, lstrlen(szBuf));
}
EndPaint(hWnd, &ps);
break;
case WM_INITMENU:
CheckMenuItem(wParam, IDM_OPTIONSSTATUS, MF_BYCOMMAND |
(GETCLSEB(hWnd, CLSEB, fStatusBarOn) ? MF_CHECKED : MF_UNCHECKED));
break;
case FW_SETMENUHELP:
SETCLSEB(hWnd, CLSEB, hWndMenuHelp, (HWND) wParam);
SETCLSEB(hWnd, CLSEB, dwMenuHelp, lParam);
if (wParam == NULL)
{
SendMessage(hWnd, FW_GETSTATBARRECT, 0, (LONG) (LPRECT) &rc);
InvalidateRect(hWnd, &rc, TRUE);
}
break;
case FW_GETMENUHELP:
dwResult = GETCLSEB(hWnd, CLSEB, dwMenuHelp);
break;
case WM_MENUSELECT:
if (lParam == MAKELONG(-1, 0))
{
SendMessage(hWnd, FW_SETMENUHELP, 0, 0);
break;
}
wTemp = 0;
switch (LOWORD(lParam) & (MF_POPUP | MF_SYSMENU))
{
case 0:
if (hWndActiveMDITChild != NULL)
{
if (fMDITChildIsMaximized)
{
wTemp = GetSubMenu(GetMenu(hWnd), 0);
if ((int) GetMenuState(wTemp, wParam, MF_BYCOMMAND) != -1)
lParam |= MF_SYSMENU;
}
SendMessage(hWndActiveMDITChild, wMsg, wParam, lParam);
wTemp = 0;
break;
}
wTemp = IDS_FRAMEMENUID + wParam;
break;
case MF_POPUP:
if (hWndActiveMDITChild != NULL)
{
if (fMDITChildIsMaximized)
{
if (wParam == GetSubMenu(GetMenu(hWnd), 0))
lParam |= MF_SYSMENU;
}
SendMessage(hWndActiveMDITChild, wMsg, wParam, lParam);
wTemp = 0;
break;
}
hMenu = GetMenu(hWnd);
wTemp = GetMenuItemCount(hMenu);
while (wTemp--)
if (GetSubMenu(hMenu, wTemp) == (HMENU) wParam) break;
wTemp += IDS_FRAMEPOPUPID + 1;
break;
case MF_SYSMENU:
wTemp = IDS_FRAMEMENUID + ((wParam & 0x0FFF) >> 4);
break;
case MF_POPUP | MF_SYSMENU:
wTemp = IDS_FRAMEPOPUPID;
break;
}
if (wTemp == 0) break;
SendMessage(hWnd, FW_SETMENUHELP, hWnd, wTemp);
break;
case WM_ENTERIDLE:
if (wParam != MSGF_MENU)
break;
if (GETCLSEB(hWnd, CLSEB, hWndMenuHelp) == -1)
break;
SendMessage(hWnd, FW_GETSTATBARRECT, 0, (LONG) (LPRECT) &rc);
InvalidateRect(hWnd, &rc, TRUE);
BeginPaint(hWnd, &ps);
SetBkMode(ps.hdc, TRANSPARENT);
SendMessage((HWND) GETCLSEB(hWnd, CLSEB, hWndMenuHelp),
AW_PAINTMENUHELP, 0, (LONG) (LPPAINTSTRUCT) &ps);
EndPaint(hWnd, &ps);
SETCLSEB(hWnd, CLSEB, hWndMenuHelp, (HWND) -1);
break;
case AW_PAINTMENUHELP:
dwResult = SendMessage(hWnd, FW_GETMENUHELP, 0, 0);
((LPPAINTSTRUCT) lParam)->rcPaint.top += (int)
SendMessage(hWnd, FW_DRAWSTATUSDIVIDE, 0,
(LONG) (LPPAINTSTRUCT) lParam);
LoadString(g_hInstance, LOWORD(dwResult), szBuf, sizeof(szBuf));
TextOut(((LPPAINTSTRUCT) lParam)->hdc,
0, ((LPPAINTSTRUCT) lParam)->rcPaint.top, szBuf, lstrlen(szBuf));
break;
case WM_COMMAND:
if (wParam >= IDM_WINDOWCHILD)
{
fCallDefProc = TRUE;
break;
}
switch (wParam)
{
case IDM_FILEOPENTHREAD:
wTemp = GETCLSEB(hWnd, CLSEB, wNumThreads) + 1;
SETCLSEB(hWnd, CLSEB, wNumThreads, wTemp);
wsprintf(szBuf, "Thread%d", wTemp);
CreateMDITChild("Thread", szBuf, 0,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
g_hWndMDITClient, g_hInstance, 0);
break;
case IDM_OPTIONSSTATUS:
wTemp = !GETCLSEB(hWnd, CLSEB, fStatusBarOn);
SETCLSEB(hWnd, CLSEB, fStatusBarOn, wTemp);
SendMessage(hWnd, FW_RESIZEMDITCLIENT, 0, 0);
break;
case IDM_EXIT:
SendMessage(hWnd, WM_CLOSE, 0, 0L);
break;
case IDM_HELPINDEX:
case IDM_HELPKEYBOARD:
case IDM_HELPCOMMANDS:
case IDM_HELPPROCEDURES:
case IDM_HELPUSINGHELP:
MessageBox(hWnd, "Option not implemented.", g_szAppName, MB_OK);
break;
case IDM_ABOUT:
fpProc = MakeProcInstance(AboutProc, g_hInstance);
DialogBox(g_hInstance, "About", hWnd, fpProc);
FreeProcInstance(fpProc);
break;
case IDM_WINDOWTILEVERT:
TileVertically(g_hWndMDITClient);
break;
case IDM_WINDOWTILEHORIZ:
SendMessage(g_hWndMDITClient, WM_MDITILE, 0, 0);
break;
case IDM_WINDOWCASCADE:
SendMessage(g_hWndMDITClient, WM_MDICASCADE, 0, 0);
break;
case IDM_WINDOWARRANGEICONS:
SendMessage(g_hWndMDITClient, WM_MDIICONARRANGE, 0, 0);
break;
default:
SendMessage(hWndActiveMDITChild, wMsg, wParam, lParam);
break;
}
break;
default:
fCallDefProc = TRUE;
break;
}
if (fCallDefProc)
dwResult = DefFrameProc(hWnd, g_hWndMDITClient, wMsg, wParam, lParam);
return(dwResult);
}
BOOL FAR PASCAL RegisterFrameWndClass (void)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = FrameWndProc;
wc.cbClsExtra = sizeof(CLSEB);
wc.cbWndExtra = 0;
wc.hInstance = g_hInstance;
wc.hIcon = LoadIcon(g_hInstance, _szClassName);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = COLOR_WINDOW + 1;
wc.lpszMenuName = _szClassName;
wc.lpszClassName = _szClassName;
return(RegisterClass(&wc));
}
void NEAR PASCAL TileVertically (HWND hWndMDITClient)
{
int nNumWndsOnRow, nOpenMDITChildren = 0, nTopOfBottomIconRow = 0;
int nCrntCol, nColWidth, nCrntRow, nNumRows, nRowHeight, nMinWndHeight;
HWND hWndChild;
HANDLE hWinPosInfo;
RECT rc;
POINT Point;
DWORD dwChildInfo;
ShowScrollBar(hWndMDITClient, SB_BOTH, 0);
SendMessage(hWndMDITClient, WM_MDIICONARRANGE, 0, 0);
hWndChild = GetWindow(hWndMDITClient, GW_CHILD);
do
{
if (IsIconic(hWndChild) && GetWindow(hWndChild, GW_OWNER) == NULL)
{
GetWindowRect(hWndChild, &rc);
nTopOfBottomIconRow = max(nTopOfBottomIconRow, rc.top);
}
if (!IsIconic(hWndChild) && GetWindow(hWndChild, GW_OWNER) == NULL)
++nOpenMDITChildren;
} while ((hWndChild = GetWindow(hWndChild, GW_HWNDNEXT)) != NULL);
if (nOpenMDITChildren == 0)
return;
GetClientRect(hWndMDITClient, &rc);
if (nTopOfBottomIconRow)
{
Point.x = 0; Point.y = nTopOfBottomIconRow;
ScreenToClient(hWndMDITClient, &Point);
rc.bottom = Point.y;
}
dwChildInfo = SendMessage(hWndMDITClient, WM_MDIGETACTIVE, 0, 0);
if (HIWORD(dwChildInfo) == 1)
ShowWindow(LOWORD(dwChildInfo), SW_RESTORE);
nMinWndHeight = max(1, rc.bottom / (5 * GetSystemMetrics(SM_CYCAPTION)));
nNumRows = min(nOpenMDITChildren, nMinWndHeight);
nRowHeight = rc.bottom / nNumRows;
hWndChild = GetWindow(hWndMDITClient, GW_CHILD);
hWinPosInfo = BeginDeferWindowPos(nOpenMDITChildren);
for (nCrntRow = 0; nCrntRow < nNumRows; nCrntRow++)
{
nNumWndsOnRow = nOpenMDITChildren / nNumRows +
((nOpenMDITChildren % nNumRows > (nNumRows - (nCrntRow + 1))) ? 1 : 0);
nColWidth = rc.right / nNumWndsOnRow;
for (nCrntCol = 0; nCrntCol < nNumWndsOnRow; )
{
if (!IsIconic(hWndChild) && GetWindow(hWndChild, GW_OWNER) == NULL)
{
hWinPosInfo = DeferWindowPos(hWinPosInfo, hWndChild, NULL,
nCrntCol * nColWidth, nCrntRow * nRowHeight, nColWidth,
nRowHeight, SWP_NOACTIVATE | SWP_NOZORDER);
nCrntCol++;
}
hWndChild = GetWindow(hWndChild, GW_HWNDNEXT);
}
}
EndDeferWindowPos(hWinPosInfo);
}